package app.Servidor;

import java.net.UnknownHostException;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Pedro Santos
 */
public class ListaSender implements Runnable {

    private Servidor server;

    public ListaSender(Servidor server) {
        this.server = server;
    }

    @Override
    public void run() {
        while (true) {
            Collection<Cliente> values = server.getListaClientes().values();
            for (Cliente cliente : values) {
                try {
                    this.server.enviarLista(cliente.getIp());
                } catch (UnknownHostException ex) {
                    Logger.getLogger(ListaSender.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    Thread.sleep(400);
                } catch (InterruptedException ex) {
                    Logger.getLogger(ListaSender.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(ListaSender.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
